/*
 * @Author: xiaosihan 
 * @Date: 2024-07-14 20:34:07 
 * @Last Modified by: xiaosihan
 * @Last Modified time: 2024-10-07 07:51:28
 */

import { autorun } from "mobx";
import { ReactNode, useEffect, useRef, useState } from "react";
import styles from "./factoryLayer.module.less";

import {
    AppstoreOutlined,
    ContainerOutlined,
    DesktopOutlined,
    MailOutlined,
    PieChartOutlined
} from '@ant-design/icons';
import hashHistory from "@hashHistory";
import type { MenuProps } from 'antd';
import { Menu } from 'antd';
import factoryStore from "../factoryStore";
import FactoryLogin from "../FactoryLogin/FactoryLogin";

type MenuItem = Required<MenuProps>['items'][number];

const items: MenuItem[] = [
    { key: 'home', icon: <PieChartOutlined />, label: "返回主页" },
    { key: '1', icon: <PieChartOutlined />, label: '首页统计' },
    { key: '2', icon: <DesktopOutlined />, label: '报价大厅' },
    { key: '3', icon: <ContainerOutlined />, label: '我的报价' },
    { key: 'sub1', icon: <MailOutlined />, label: '我的订单', },
    { key: 'sub2', icon: <AppstoreOutlined />, label: '零件库', },
];

interface Iprops {
    children?: ReactNode
}

// 工厂管理系统布局
export default function FactoryLayer(props: Iprops) {
    const dom = useRef<HTMLDivElement | null>(null);
    const [data, setData] = useState({});
    const [isLogin, setIsLogin] = useState(factoryStore.isLogin);

    useEffect(() => {
        factoryStore.getFactoryUser();
    }, []);

    useEffect(() => autorun(() => {
        setIsLogin(factoryStore.isLogin);
    }, { delay: 10 }), []);

    return (
        < div className={styles.factoryLayer} >
            {isLogin === false && <FactoryLogin />}

            {
                false && <>
                    <div className={styles.left} >
                        <Menu
                            onSelect={(e: any) => {
                                if (["home"].includes(e.key)) {
                                    hashHistory.push("/")
                                } else {

                                }
                            }}
                            className={styles.menu}
                            defaultSelectedKeys={['1']}
                            defaultOpenKeys={['sub1']}
                            mode="inline"
                            theme="dark"
                            items={items}
                        />
                    </div>

                    {/* <div className={styles.right} ></div>*/}

                </>
            }

            {isLogin === true && props.children}
        </div >
    );

}